<template>
  <div class="container">
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>一卡通管理</el-breadcrumb-item>
      <el-breadcrumb-item>挂失列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- card -->
    <el-card>
      <!-- alert提示区域 -->
      <el-alert title="tips：信息宝贵，谨慎操作" type="success" :closable="false"></el-alert>
      <!-- 搜索框区域 -->
      <!-- <el-row :gutter="30">
        <el-col :span="12">
          <el-input placeholder="请输入内容" v-model="queryInfo.keyWord" clearable @clear="getLostList">
            <el-button slot="append" icon="el-icon-search" @click="getLostList"></el-button>
          </el-input>
        </el-col>
      </el-row> -->
      <el-table :data="lostList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="姓名" prop="studentName"></el-table-column>
        <el-table-column label="校号" prop="studentNum"></el-table-column>
        <el-table-column label="院系" prop="department"></el-table-column>
        <el-table-column label="班级" prop="classes"></el-table-column>
        <el-table-column label="手机号" prop="studentPhone"></el-table-column>
        <el-table-column label="挂失原因" prop="cause"></el-table-column>
        <el-table-column label="解除冻结状态">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="relieveCard(scope.row.id)">解除</el-button>
          </template>
        </el-table-column>
        <el-table-column label="补办校园卡">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="reapplyCard(scope.row.id)">补办</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import commonServe from '../../api/services/common.serve'
export default {
  data() {
    return {
      lostList: [],
      queryInfo: {}
    }
  },
  created() {
    this.getLostList()
  },
  methods: {
    // 获取挂失列表
    getLostList() {
      commonServe
        .getLostCard()
        .then((res) => {
          console.log(res)
          if (res.code === 200) {
            this.lostList = res.data.list
          } else {
            this.$message.warning('获取挂失列表失败')
          }
        })
        .catch((err) => {
          this.$message.warning(err.message)
        })
    },
    // 解除校园卡挂失状态
    async relieveCard(val) {
      const confirmResult = await this.$confirm('确认解除一卡通冻结状态, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch((err) => err)
      console.log(confirmResult)
      if (confirmResult !== 'confirm') {
        return this.$message.info('已经取消解除')
      }
      // 调用接口解除挂失
      commonServe
        .reapplyOrRelieveCard(val)
        .then((res) => {
          if (res.code === 200) {
            this.$message.success('解除挂失成功')
            this.getLostList()
          } else {
            this.$message.warning('解除挂失失败')
          }
        })
        .catch((err) => {
          this.$message.warning(err.message)
        })
    },
    // 补办校园卡
    async reapplyCard(val) {
      const confirmResult = await this.$confirm('确认补办一卡通?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch((err) => err)
      console.log(confirmResult)
      if (confirmResult !== 'confirm') {
        return this.$message.info('已经取消补办')
      }
      // 调用接口
      commonServe
        .reapplyOrRelieveCard(val)
        .then((res) => {
          if (res.code === 200) {
            this.$message.success('补办一卡通成功')
            this.getLostList()
          } else {
            this.$message.warning('补办一卡通失败')
          }
        })
        .catch((err) => {
          this.$message.warning(err.message)
        })
    }
  }
}
</script>

<style lang="less" scoped></style>
